package com.yunji.cabinet.mapper;

import com.github.yulichang.base.MPJBaseMapper;
import com.yunji.cabinet.domain.ContainerCell;
import com.yunji.cabinet.vo.CellProductCountVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.cabinet.mapper
 * @FileName CabinetCellMapper.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-04-01 19:50:14
 * @Description 货柜格子数据交互
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-01 19:50:14		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
public interface CabinetCellMapper extends MPJBaseMapper<ContainerCell> {
    /**
     * @return int 新增记录数
     * @Title create
     * @Desc 新增货柜格子
     * @Date 2024-04-09 19:49:14
     * @Param cell 格子信息
     */
    int create(ContainerCell cell);

    /**
     * @return int 新增记录数
     * @Title update
     * @Desc 新增货柜格子
     * @Date 2024-04-09 19:49:14
     * @Param cell 格子信息
     */
    int update(ContainerCell cell);

    /**
     * @return int 删除记录数
     * @Title delete
     * @Desc 删除格子信息
     * @Date 2024-04-09 19:48:32
     * @Param cell 修改信息
     * @Param ids 过滤条件
     */
    int delete(@Param("bean") ContainerCell cell, @Param("ids") Long... ids);

    /**
     * @return List<ContainerCell> 货柜格子信息
     * @Title search
     * @Desc 获取货柜格子信息
     * @Date 2024-04-10 09:36:34
     * @Param cabinetIds 货柜ID数组
     */
    List<ContainerCell> search(@Param("belongId") Long belongId, @Param("ids") Long... cabinetIds);


    /**
     * @return List<ContainerCell> 货柜格子信息
     * @Title select
     * @Desc 获取货柜格子信息
     * @Date 2024-04-10 09:36:34
     * @Param cabinetIds 货柜ID数组
     */
    List<ContainerCell> select(@Param("belongId") Long belongId, @Param("ids") List<Long> cabinetIds);

    List<ContainerCell> selectCells(@Param("ids") List<Long> cabinetIds);


    /**
     * @return int 商品数量
     * @Title getRemainProduct
     * @Desc 获取剩下商品数量
     * @Date 2024-04-12 18:11:32
     * @Param containerId 货柜ID
     */
    @Select(" <script>  SELECT count(1)" +
            "        FROM t_container_cell" +
            "        WHERE del_flag = 0" +
            "          AND `status` = 1" +
            "          AND container_id = #{containerId} </script>")
    int getRemainProduct(Long containerId);

    @Select(" <script>   SELECT cc.product_id AS productId," +
            "               count(*)      AS nums" +
            "        FROM t_container_cell cc" +
            "                 LEFT JOIN" +
            "             t_container con" +
            "             ON cc.container_id = con.container_id" +
            "        WHERE cc.del_flag = 0" +
            "          AND con.del_flag = 0" +
            "          AND cc.`status` = 1" +
            "          AND con.belong_id = #{belongId}" +
            "        GROUP BY cc.product_id </script>")
    List<CellProductCountVO> countCellProduct(Long belongId);
}
